import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { PartialConsult } from '@/types/consult' //问诊记录
import type { ConsultType } from '@/enums/index' //问诊类型

export const useConsultStore = defineStore(
  // 仓库模块名
  'cp-consult',
  // 仓库状态管理
  () => {
    // 问诊记录数据
    const consult = ref<PartialConsult>({})
    // 设置问诊类型
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    // 设置问诊级别
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }
    // 设置科室类别
    const setDep = (id: string) => {
      consult.value.depId = id
    }
    // 设置病情描述
    const setIllness = (
      illness: Pick<
        PartialConsult,
        'illnessDesc' | 'illnessTime' | 'consultFlag' | 'pictures'
      >
    ) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }
    // 设置患者
    const setPatient = (id: string) => {
      consult.value.patientId = id
    }
    // 设置支付订单id
    const setCoupon = (couponId: string) => {
      consult.value.couponId = couponId
    }
    // 清空问诊订单信息
    const clear = () => {
      consult.value = {}
    }

    return {
      consult,
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCoupon,
      clear
    }
  },
  // 持久化
  {
    persist: true
  }
)
